package com.itfreer.utils.hibernate;

import java.util.Map;
import java.util.Set;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;

/**
 * 定义排序参数转换类
 */
public class OrderConvertUtils {

	/**
	 * 排序值进行转换
	 * @param criteriaBuilder
	 * @param rootFrom
	 * @param criteriaQuery
	 * @param order
	 */
	public static void convert(
			Criteria crit,
			Map<String, Integer> order){
		
		if(order==null || order.size()<=0){
			return;
		}
		
		Set<String> keys = order.keySet();
		for(String key : keys){
			// 1 为降序
			if(order.get(key).equals(1)){
				crit.addOrder(Order.desc(key));
			} else {
				// 0 或其它为升序
				crit.addOrder(Order.asc(key));
			}
		}
	}
}
